function newcoord=changecoord_3(s1, s2,a1, a2, a3)
  %Take a 3-D matrix A with s1=size(A,1), s2=size(A,2), s3=size(A,3)
  %Consider
  %B=reshape(A, s1*s2*s3,1);

  %Take the coordinates a1, a2, a3
  %This function gives the position in B of A(a1,a2,a3)
  newcoord = a1 + ( a2-1 + (a3-1)*s2 ) * s1; 
end